/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2018
 */

package com.bm.console.business.impl;

import com.sys.console.cookie.Constant_Cookie;
import com.sys.console.pojo.Sys_User;
import com.sys.object.common.page.PageBean;

import com.bm.console.business.WebJobService;
import com.bm.console.pojo.WebJob;
import com.bm.console.pojo.mapper.WebJobMapper;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sys.object.common.page.PageBean;

import javax.servlet.http.HttpServletRequest;

@Service
public class WebJobServiceImpl implements WebJobService {

	@Autowired
	WebJobMapper webJobMapper;

	@Autowired
	private HttpServletRequest request;

	@Override
	public PageBean queryPageList(WebJob entity, PageBean page) throws Exception {
		int rowCount = webJobMapper.selectByPageCount(entity);
		page.setRowCount(rowCount);
		entity.setOffset(page.getStartRow());
		entity.setLimit(page.getPerpage());
		page.setList(webJobMapper.selectByPage(entity));
		return page;
	}

	public WebJob queryByPrimaryKey(Integer id) throws Exception {
		return webJobMapper.selectByPrimaryKey(id);
	}

	public int saveOrUpdate(WebJob entity) throws Exception {
		Sys_User currentUser = (Sys_User)request.getSession().getAttribute(Constant_Cookie.CURRENT_USER_SESSION);
		if (entity.getId() != null && entity.getId() > 0) {
			entity.setUpdateTime(new Date());
			entity.setUpdateId(currentUser.getUid());
			return this.webJobMapper.updateByPrimaryKeySelective(entity);
		}
		entity.setCreateTime(new Date());
		entity.setCreateId(currentUser.getUid());
		return this.webJobMapper.insert(entity);
	}

	public int remove(Integer id) throws Exception {
		return this.webJobMapper.deleteByPrimaryKey(id);
	}

	public int delete(Integer id) throws Exception {
		return this.webJobMapper.deleteByPrimaryKey(id);
	}

	public int updateStatus(WebJob entity) throws Exception {
		return this.webJobMapper.updateByPrimaryKeySelective(entity);
	}

	public int updateStatus(String status, String[] ids) throws Exception {

		return 0;
	}

}
